/*
 * file: matrix_utils.c
 * author: adapted from CSE6230
 *
 */

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include "matrix_utils.h"

bool verify_matrix(int m, int n, double *A, double *B)
{
    //check every element of A and compare it to some eps distance
    //from B
    int row,col;
    for (col=0; col<n; col++) {
        for (row=0; row<m; row++) {
            int index = (col*m)+row;
            double a = A[index];
            double b = B[index];

            if (a<b-EPS) { return false; }
            if (a>b+EPS) { return false; }
        }
    }
    return true;
}

void print_matrix(int rows, int cols, double *mat)
{
    int r,c;
    for (r=0; r<rows; r++) {
        for (c=0; c<cols; c++) {       
            int index = (c*rows)+r;
            printf("%.11f ", mat[index]);
        }
        printf("\n");
    }
}
void random_matrix(int rows, int cols, double *mat)
{
    int r,c;
    for (c=0; c<cols; c++) {
        for (r=0; r<rows; r++) {
            int index = (c*rows)+r;
            mat[index] = round(10.0*rand() / (RAND_MAX+1.0));
        }
    }
}
void zero_matrix(int rows, int cols, double *mat)
{
    int r,c;
    for (c=0; c<cols; c++) {
        for (r=0; r<rows; r++) {
            int index = (c*rows)+r;
            mat[index] = 0.0;
        }
    }
}
void copy_matrix(int rows, int cols, double *src, double *dest)
{
    int r,c;

    for (c=0; c<cols; c++) {
        for (r=0; r<rows; r++) {
            dest[c*rows+r] = src[c*rows+r];
        }
    }
}

